package com.ctw.mapmycity;

import java.util.List;

import android.app.Activity;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;

import com.google.android.gms.maps.model.LatLng;

public class GetAddressService extends AsyncTask<Void, Void, String> {

	private Activity context;
	private LatLng point; 
	private List<Address> address = null;
	private String addressString = null;

	
	public GetAddressService(LatLng point, Activity context){
		this.context = context;
		this.point = point;
	}

	@Override
	protected String doInBackground(Void... params) {
		Geocoder geocoder = new Geocoder(context);
		
			try {
				address = (geocoder.getFromLocation(getPoint().latitude, getPoint().longitude, 1));
//				setAddressString(address.toString());
//				System.out.println("addressString: " + addressString);
			} catch (Exception e) {
				e.printStackTrace();
			}
		return null;
	}

	@Override
	protected void onPostExecute(final String authToken) {
		
		System.out.println(address.toString());
		
//		try {
//			setAddressString(get());
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (ExecutionException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}

	@Override
	protected void onCancelled() {

	}

	public Activity getContext() {
		return context;
	}

	public void setContext(Activity context) {
		this.context = context;
	}

	public LatLng getPoint() {
		return point;
	}

	public void setPoint(LatLng point) {
		this.point = point;
	}

	public String getAddressString() {
		return addressString;
	}

	public void setAddressString(String addressString) {
		this.addressString = addressString;
	}


	
}